#include "CreditsMenuState.h"
#include "MainMenuState.h"
#include "OptionsMenuState.h"
#include "BitmapFont.h"
#include "Game.h"
#include "CSGD_TextureManager.h"
#include "CSGD_DirectInput.h"
#include "CSGD_XAudio2.h"
#include "../resource.h"

/////////////////////////////////////////////////////////////////////////////
// Function		: CCreditsMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CCreditsMenuState::CCreditsMenuState(void)
{	
	m_nBackgroundImg = -1;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: ~CCreditsMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CCreditsMenuState::~CCreditsMenuState(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// Function		: GetInstance
// Return		: CCreditsMenuState* 
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CCreditsMenuState* CCreditsMenuState::GetInstance( void )
{
	static CCreditsMenuState s_Instance;

	return &s_Instance;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Enter
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CCreditsMenuState::Enter( void )
{
	m_nBackgroundImg = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/MenuBackground.png"));

	if(COptionsMenuState::GetInstance()->ReturnEng())
	{
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Credit1, Credit1, 100);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Credit2, Credit2, 100);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Credit3, Credit3, 50);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_EscToMain, EscToMain, 50);
	}
	else
	{
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Credit1, Credit1, 100);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Credit2, Credit2, 100);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Credit3, Credit3, 50);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_EscToMain, EscToMain, 50);
	}

	TrueCredit2 = "";
	TrueCredit3 = "";
	TrueEscTMain = "";

	for (int character = 0; character < 100; character++)
	{
		if(Credit2[character] != NULL)
			TrueCredit2 += (char)Credit2[character];
		else
			break;
	}

	for (int character = 0; character < 50; character++)
	{
		if(Credit3[character] != NULL)
			TrueCredit3 += (char)Credit3[character];
		else
			break;
	}

	for (int character = 0; character < 50; character++)
	{
		if(EscToMain[character] != NULL)
			TrueEscTMain += (char)EscToMain[character];
		else
			break;
	}
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Exit
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CCreditsMenuState::Exit ( void )
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nBackgroundImg);
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Input
// Return		: bool
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
bool CCreditsMenuState::Input( void )
{
	CSGD_DirectInput* m_pDI = CSGD_DirectInput::GetInstance();

	if( m_pDI->KeyPressed( DIK_ESCAPE ) == true || m_pDI->JoystickButtonPressed(1,0))
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		CSGD_XAudio2::GetInstance()->SFXPlaySound(CGame::GetInstance()->GetConfirmID());
	}

	return true;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Update
// Parameters	: fElapsedTime - The ammount of time that has passed since last update
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CCreditsMenuState::Update( float fElapsedTime )
{
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Render
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CCreditsMenuState::Render( void )
{
	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImg,0,0);

	CBitmapFont* font = CGame::GetInstance()->GetFont();

	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImg, 0,0, 1.0f,1.0f);
	font->Draw(EscToMain,
		CGame::GetInstance()->GetScreenMidPoint(TrueEscTMain,1.0f), 568, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw(Credit1, 
		125, 50, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Credit2, 
		175, 150, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Credit3, 
		CGame::GetInstance()->GetScreenMidPoint(TrueCredit3,1.0f), 400, 1.0f, D3DCOLOR_ARGB( 255, 255, 0, 0 ) );
}